package com.yuhang.demo.util;

import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.*;
import java.util.Map.Entry;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.go2.shipping.common.encrypt.AES;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import sun.misc.BASE64Encoder;

public class PostUtil {
    public static String httpGet(String url) {
        HttpClient client = HttpClients.createDefault();

        try {
            HttpGet httpRequst = new HttpGet(url);
            httpRequst.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
            HttpResponse res = client.execute(httpRequst);
            HttpEntity entity = res.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8");

            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String httpPostWz(String url, List<NameValuePair> formparams) throws IOException {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;
    }

    /**
     * @Date 2016年7月27日
     * @desc post请求
     */
    public static String httpPost(String url, List<NameValuePair> formparams) throws IOException {
//		formparams.add(new BasicNameValuePair("version", "2.0"));
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                HttpEntity entity = response.getEntity();
                System.out.println(entity != null ? EntityUtils.toString(entity, "utf-8") : "");
                return null;
            }
        });
        return response;
    }

    public static String httpApp1b(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("sign", s.sign(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }

    public static String httpAppVm(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("timestamp", new Date().getTime());
        params.put("sign", s.cdBacks(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }

    public static String vmi(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("timestamp", new Date().getTime());
        params.put("sign", s.vm(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }


    public static String httpApp(String url, Map<String, Object> params) throws Exception {
        params.put("timestamp", new Date().getTime());
        SignUtil s = new SignUtil();
        params.put("sign", s.sign(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        List<String> a= new ArrayList<>();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));


            a.add(entry.getKey()+"="+String.valueOf(entry.getValue()));
        }


        System.out.println(StringUtils.join(a,"&"));

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }


    public static String httpPostBack(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("sign", s.signBack(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }


    public static String httpPostPrd(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("sign", s.sign(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }


    public static String httpPostBody(String url, String json) throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        httpPost.addHeader("Content-Type", "application/json");
        httpPost.setEntity(new StringEntity(json, "UTF-8"));
        CloseableHttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        String responseContent = EntityUtils.toString(entity, "UTF-8");
        response.close();
        httpClient.close();
        return responseContent;
    }


    public static String httpPostBodyImg(String url, String json) throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        httpPost.addHeader("Content-Type", "application/json");
        httpPost.setEntity(new StringEntity(json, "UTF-8"));
        CloseableHttpResponse response = httpClient.execute(httpPost);
        byte[] data = EntityUtils.toByteArray(response.getEntity());// 将图片或者文件转化成数组的形式
        // 图片流转base64
        BASE64Encoder encoder = new BASE64Encoder();
        String imageBase64 = "data:image/png;base64," + encoder.encode(data);
        response.close();
        httpClient.close();
        return imageBase64;
    }

    public static String httpPost1B(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("sign", s.signApp1B(params, "UTF-8"));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }


    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 20; i++) {
            String url = "https://a2.liao4fun.com/";
            long begin = System.currentTimeMillis();
            PostUtil.httpGet(url);
            long end = System.currentTimeMillis();

            System.out.println(end - begin);
        }
    }


    public static String httpPostIntegral(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        params.put("timestamp", System.currentTimeMillis());
        params.put("sign", s.signApp1B(params, "UTF-8"));

        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        String sb = "";
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
            sb = sb + entry.getKey() + "=" + entry.getValue() + "&";
        }
        long b = System.currentTimeMillis();
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        System.out.println("耗时：" + (System.currentTimeMillis() - b));
        return response;

    }


    public static String httpAppPay(String url, Map<String, Object> params) throws Exception {
        SignUtil s = new SignUtil();
        AES aes = new AES("cqgsb2020y06m30dpay");
        params.put("timestamp", aes.encrypt(System.currentTimeMillis() + ""));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            @Override
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;

    }

    public static String httpPostWithHeader(String url, List<NameValuePair> formparams, String headerToken) throws IOException {
//		formparams.add(new BasicNameValuePair("version", "2.0"));
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        post.setHeader("token", headerToken);
        post.setHeader("source", "e3hw");
        post.setHeader("appVersion", "4.0.0");
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                HttpEntity entity = response.getEntity();
                System.out.println(entity != null ? EntityUtils.toString(entity, "utf-8") : "");
                return null;
            }
        });
        return response;
    }


    public static String httpGetWithr(String url, List<NameValuePair> formparams, String headerToken) throws IOException {
        HttpClient client = HttpClients.createDefault();

        try {
            HttpGet httpRequst = new HttpGet(url);
            httpRequst.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
            httpRequst.setHeader("token", headerToken);
            HttpResponse res = client.execute(httpRequst);
            HttpEntity entity = res.getEntity();
            String result = EntityUtils.toString(entity, "UTF-8");

            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static String httpGetWithHeader(String url, Map<String, Object> params, String headerToken) throws IOException {
//		formparams.add(new BasicNameValuePair("version", "2.0"));
        CloseableHttpClient client = HttpClients.createDefault();
        HttpGet post = new HttpGet(url);
        post.setHeader("token", headerToken);

        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                HttpEntity entity = response.getEntity();
                System.out.println(entity != null ? EntityUtils.toString(entity, "utf-8") : "");
                return null;
            }
        });
        return response;
    }


    public static String httpServiceFee(String url, Map<String, Object> params) throws Exception {
        params.put("timestamp", new Date().getTime());
        params.put("sign", SignUtil.signServiceFee(params));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        List<String> aa = new ArrayList<>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));

            aa.add(entry.getKey() + "=" + entry.getValue());
        }
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            @Override
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;
    }


    public static String httpServiceFeeGet(String url, Map<String, Object> params) throws Exception {
        CloseableHttpClient client = HttpClients.createDefault();
        long x= System.currentTimeMillis();
        params.put("timestamp", x+"");
        URIBuilder uriBuilder = new URIBuilder(url);
        /** 第一种添加参数的形式 */
        uriBuilder.addParameter("timestamp", x+"");
        uriBuilder.addParameter("sign", SignUtil.signServiceFee(params));
        /** 第二种添加参数的形式 */
//        List<NameValuePair> list = new LinkedList<>();
//        BasicNameValuePair param1 = new BasicNameValuePair("timestamp", new Date().getTime() + "");
//        BasicNameValuePair param2 = new BasicNameValuePair("sign", SignUtil.signServiceFee(params));
//        list.add(param1);
//        list.add(param2);
//        uriBuilder.setParameters(list);
        HttpGet httpGet = new HttpGet(uriBuilder.build());
        // 执行请求
        CloseableHttpResponse response = null;
        response = client.execute(httpGet);
        // 获得响应的实体对象
        HttpEntity entity = response.getEntity();
        // 使用Apache提供的工具类进行转换成字符串
        String entityStr = EntityUtils.toString(entity, "UTF-8");
        return entityStr;
    }


    public static String httpCloud(String url, Map<String, Object> params) throws Exception {

        String secret = "go2CN|20220119wearethebest";
        String nonce = UUID.randomUUID().toString();
        long timestamp = System.currentTimeMillis();
        String key = SecureUtil.sha1(secret + nonce + timestamp);
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        List<String> aa = new ArrayList<>();
        Iterator<Entry<String, Object>> iter = params.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Object> entry = iter.next();
            formparams
                    .add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())));

            aa.add(entry.getKey() + "=" + entry.getValue());
        }

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setHeader("nonce", nonce);
        post.setHeader("timestamp", String.valueOf(timestamp));
        post.setHeader("sign", key);
        post.setEntity(uefEntity);
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;
    }


    public static String httpCloudJSON(String url, Map<String, Object> params) throws Exception {

        String secret = "go2CN|20220119wearethebest";
        String nonce = UUID.randomUUID().toString();
        long timestamp = System.currentTimeMillis();
        String key = SecureUtil.sha1(secret + nonce + timestamp);
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        post.setHeader("sign",key);
        post.setHeader("nonce", nonce);
        post.setHeader("timestamp", timestamp+"");

        post.setEntity(new StringEntity(JSON.toJSONString(params), "utf-8"));
        String response = client.execute(post, new ResponseHandler<String>() {
            public String handleResponse(HttpResponse response) throws IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity, "utf-8") : null;
                } else {
                    System.out.println(response);
                }
                System.out.println(status);
                return null;
            }
        });
        return response;
    }
}




